package com.dream.technology.components.collarData;



import com.dream.technology.components.context.FlowContext;

import java.util.List;

/**
 * 描述：外部请求封装
 *
 * @author chen_q_i@163.com
 * 2018/12/26 : 16:27.
 * @version : 1.0
 */
public interface BaseCollarService {

    void execute(FlowContext flowContext) throws Exception;


    default boolean isEmpty(Object obj) {
        if (obj == null) {
            return true;
        }
        if ((obj instanceof List)) {
            return ((List) obj).size() == 0;
        }
        if ((obj instanceof String)) {
            return ((String) obj).trim().equals("");
        }
        return false;
    }


    /**
     * 保存结果到flowContext
     *
     * @param b
     * @param flowContext
     * @param className
     */
    default void saveResult(boolean b, FlowContext flowContext, String className) {

//        className = ZYStringUtils.toLowerCaseFirstOne(className);
        flowContext.put(className, b);
        flowContext.putServiceNames(className);
    }

      /**
     * 保存结果到flowContext
     *
     * @param object
     * @param flowContext
     * @param className
     */
    default void saveResultObj(Object object, FlowContext flowContext, String className) {

//        className = ZYStringUtils.toLowerCaseFirstOne(className);
        flowContext.put(className, object);
        flowContext.putServiceNames(className);
    }



}
